package cn.eyecool.qmuidemo.fragment;

import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment;

import com.qmuiteam.qmui.layout.QMUIConstraintLayout;
import com.qmuiteam.qmui.layout.QMUIFrameLayout;
import com.qmuiteam.qmui.layout.QMUIRelativeLayout;
import com.qmuiteam.qmui.widget.QMUITopBar;

import cn.eyecool.qmuidemo.MainActivity;
import cn.eyecool.qmuidemo.R;

/**
 * A simple {@link Fragment} subclass.
 * Use the {@link QMUILayoutFragment#newInstance} factory method to
 * create an instance of this fragment.
 */
public class QMUILayoutFragment extends BaseFragment {

    private String TAG = MainActivity.TAG;

    // TODO: Rename parameter arguments, choose names that match
    // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";

    // TODO: Rename and change types of parameters
    private String mParam1;
    private String mParam2;

    private View mStatusView;
    private QMUITopBar mTopBar;
    private QMUIFrameLayout mQMUIFL;
    private QMUIRelativeLayout mQMUIRL;
    private QMUIConstraintLayout mQMUICL;

    public QMUILayoutFragment() {
        // Required empty public constructor
    }

    /**
     * Use this factory method to create a new instance of
     * this fragment using the provided parameters.
     *
     * @param param1 Parameter 1.
     * @param param2 Parameter 2.
     * @return A new instance of fragment QMUILayoutFragment.
     */
    // TODO: Rename and change types and number of parameters
    public static QMUILayoutFragment newInstance(String param1, String param2) {
        QMUILayoutFragment fragment = new QMUILayoutFragment();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, param1);
        args.putString(ARG_PARAM2, param2);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mParam1 = getArguments().getString(ARG_PARAM1);
            mParam2 = getArguments().getString(ARG_PARAM2);
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return super.onCreateView(inflater, container, savedInstanceState);
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        mStatusView = findViewById(R.id.fake_status_bar);

        mTopBar = findViewById(R.id.topbar);
        mTopBar.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.app_color_blue));
        mTopBar.setTitle("QMUILayout");
        mTopBar.addLeftBackImageButton().setOnClickListener(v -> back());

        mQMUIFL = findViewById(R.id.qmuiFL);
        mQMUIFL.setRadius(20);
        mQMUIFL.setElevation(10f);

        mQMUIRL = findViewById(R.id.qmuiRL);
        mQMUIRL.setRadius(20);
        mQMUIRL.setElevation(10f);

        mQMUICL = findViewById(R.id.qmuiCL);
        mQMUICL.setRadius(20);
        mQMUICL.setElevation(10f);

        Log.i(TAG, "statusBarHeight = " + statusBarHeight);
        ViewGroup.LayoutParams lp = mStatusView.getLayoutParams();
        lp.height = statusBarHeight;
        mStatusView.setLayoutParams(lp);
    }

    @Override
    public int getLayoutId() {
        return R.layout.fragment_q_m_u_i_layout;
    }
}